// pages/mine/index.js
var app = getApp()
Page({
  help: function () {
    wx.navigateTo({
      url: '../help/index',
    })
  },
  address: function () {
    wx.navigateTo({
      url: '../newAddress/index',
    })
  },
  letters: function (e) {
    var index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: "../letters/index?index=" + index,
    })
  },
  /**
   * 页面的初始数据
   */
  data: {
    mine_list: [
      { icon: 'description', title: '全部订单' },
      { icon: 'balance-pay', title: '待付款' },
      { icon: 'logistics', title: '待收货' },
      { icon: 'flower-o', title: '待评价' }
    ],
    bar: 'https://img.yzcdn.cn/vant/cat.jpeg',
    userName: 'admin',
    num: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showShareMenu({
      // 要求小程序返回分享目标信息
      withShareTicket: true
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.userInfo !== null) {
      this.setData({
        bar: app.globalData.userInfo.avatarUrl,
        userName: app.globalData.userInfo.nickName,
      })
    }
    var arr = wx.getStorageSync('carList')
    var num = 0;
    if (arr) {
      arr.map(item => {
        num += item.sep
      })
      this.setData({
        num: num
      })
    } else {
      this.setData({
        num: ''
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (p) {
    if (p.from === 'button') {
      console.log(p.target)
    }
    console.log(p.from)
    return {
      title: '分享前端',
      imageUrl: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607765077205&di=faf7ab709399db283e730da81bf0d1b4&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F40bc4a8e62abca16af6fc839982e30bf284ccd141839b-d147cM_fw658',
      path: '/pages/oder/index'
    }
  },
  //定义此方法之后，点击右上角按钮弹出的菜单中"分享到朋友圈"按钮变为可点击
  onShareTimeline: function () {
    return {
      title: '万能的朋友圈',
      query: '../car/index',
      imageUrl: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607765684926&di=f79ef551c720b9a70a1a2bda62c8fb3a&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fforum%2Fw%3D580%2Fsign%3Dd97deea355ee3d6d22c687c373166d41%2Ff5c8d1c8a786c917f77eaf3dc53d70cf3bc757b3.jpg',
    }
  }
})